//
//  UIBarButtonItem+Extention.m
//  SinaWeibo
//
//  Created by Apple on 16/8/7.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "UIBarButtonItem+Extention.h"

@implementation UIBarButtonItem (Extention)

//同时可以将他封装到工具类里，方便其他界面使用。

/**
 *  设置自定义导航栏的左右按钮，若直接添加左右按钮，系统将默认显示蓝色tintColor
 *
 *  @param imgName 要点击按钮的图片（同时要包括高亮状态是的图片，图片名字只相差_highlighted
 *
 *  @param action 监听方法
 *
 *  @return 返回一个设置好自定义图片
 **/
+(UIBarButtonItem *)setNavItemWithImageName:(NSString *)imgName target:(id)target action:(SEL)action{
    
    UIButton *button = [[UIButton alloc]init];
    
    //设置button的图片
    [button setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
    
    NSString *highlightedName = [imgName stringByAppendingString:@"_highlighted"];
    
    [button setImage:[UIImage imageNamed:highlightedName] forState:UIControlStateHighlighted];
    
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    //设置button的文字
//    [button setTitle:title forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
//    button.titleLabel.font = [UIFont systemFontOfSize:14];
    
    //设置完后不显示, 是因为没有设置button的frame.
    [button sizeToFit];
    
    //添加button的事件.
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return btnItem;
    
}


+(UIBarButtonItem *)setNavItemWithTitle:(NSString *)title target:(id)target action:(SEL)action{
    
    UIButton *button = [[UIButton alloc]init];
    
    //设置button的文字
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    
    //设置完后不显示, 是因为没有设置button的frame.
    [button sizeToFit];
    
    //添加button的事件.
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    return btnItem;

    
}

+(UIBarButtonItem *)setNavItemWithTitleDisableColor:(NSString *)title normalColor:(UIColor *)normalColor disabledColor:(UIColor *)disabledColor target:(id)target action:(SEL)action{
    
    UIButton *button = [[UIButton alloc]init];
    
    //设置button的文字
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:normalColor forState:UIControlStateNormal];
    [button setTitleColor:disabledColor forState:UIControlStateDisabled];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    
    //设置完后不显示, 是因为没有设置button的frame.
    [button sizeToFit];
    
    //添加button的事件.
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    
    
    return btnItem;
    
    
}


+(UIBarButtonItem *)setNavItemWithTitle:(NSString *)title normalColor:(UIColor *)normalColor highlightedColor:(UIColor *)highlightedTitleColor target:(id)target action:(SEL)action{
    
    UIButton *button = [[UIButton alloc]init];
    
    //设置button的文字
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:normalColor forState:UIControlStateNormal];
    [button setTitleColor:highlightedTitleColor forState:UIControlStateHighlighted];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    
    //设置完后不显示, 是因为没有设置button的frame.
    [button sizeToFit];
    
    //添加button的事件.
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    
    
    return btnItem;
    
    
}



@end
